﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EntropiaMiningMap
{
    /// <summary>
    /// Contains data about a material and where it has been found
    /// </summary>
    class Material
    {
        /// <summary>
        /// The name of the material
        /// </summary>
        private String name;

        /// <summary>
        /// A list of material points associated with the given material
        /// </summary>
        private List<MaterialPoint> materialPoints;
        
        /// <summary>
        /// Constructor for a material
        /// </summary>
        /// <param name="n">Material name</param>
        public Material(String n)
        {
            name = n;
            materialPoints = new List<MaterialPoint>();
        }

        /// <summary>
        /// Constructor defining name and an initial material point
        /// </summary>
        /// <param name="n"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public Material(String n, int x, int y)
        {
            name = n;
            materialPoints = new List<MaterialPoint>();
            materialPoints.Add(new MaterialPoint(x, y));
        }

        /// <summary>
        /// Add a point at which a particular material was located
        /// </summary>
        /// <param name="x">x-coordinate of the material</param>
        /// <param name="y">y-coordinate of the material</param>
        public void AddPoint(int x, int y)
        {
            // Go through the existing list of materials and see whether the point exists
            foreach (MaterialPoint mp in materialPoints)
            {
                if (mp.X == x && mp.Y == y)
                {
                    mp.Occurrences = mp.Occurrences + 1;
                    return;
                }
            }

            // We did not find the point, so add to the list
            materialPoints.Add(new MaterialPoint(x, y));
        }

        /// <summary>
        /// Load a material point and attach it to this material
        /// </summary>
        /// <param name="mp">Material Point to attach</param>
        public void LoadPoint(MaterialPoint mp)
        {
            materialPoints.Add(mp);
        }

        /// <summary>
        /// Accessor for name
        /// </summary>
        public String Name
        {
            get { return name; }
        }

        /// <summary>
        /// Accessor for materialPoints
        /// </summary>
        public List<MaterialPoint> MaterialPoints
        {
            get { return materialPoints; }
        }
    }
}
